﻿using System;
using System.Collections.Generic;
using System.Data.Common.CommandTrees;
using System.Data.Objects.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.InsuranceOrder;
using ZBJF.Warranty.Common.Enums.InsuranceWarranty;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.Udesk;

namespace ZBJF.Warranty.BLL
{
    public partial class Udesk_ChatDetailService
    {
        public IQueryable<Udesk_ChatDetail> GetPagingList(ChatDetailModel model, out int total)
        {
            var expressionWhere = PredicateExtensions.True<Udesk_ChatDetail>();
            if (!string.IsNullOrEmpty(model.content))
            {
                expressionWhere = expressionWhere.And(n => n.content.Contains(model.content));
            }
            if (!string.IsNullOrEmpty(model.contentType))
            {
                expressionWhere = expressionWhere.And(n => n.contentType.Equals(model.contentType));
            }
            if (model.TimeRange.HasValue)
            {
                DateTime statTime=DateTime.Now,enDateTime=DateTime.Now;
                if (model.TimeRange.Value == 100)
                {
                    statTime = statTime.AddMonths(-1);
                }
                else if (model.TimeRange.Value == 200)
                {
                    statTime = statTime.AddMonths(-2);
                }
                else
                {
                    statTime = statTime.AddMonths(-3);
                }
                expressionWhere = expressionWhere.And(n => n.created_at>=statTime && n.created_at<=enDateTime);
            }
            if (string.IsNullOrEmpty(model.iSorts))
            {
                model.iSorts = "ID desc";
            }
            return LoadPagerEntities<Udesk_ChatDetail>(model.PageIndex, model.iDisplayLength, out total, expressionWhere, model.iSorts);
        }
    }
}
